﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Gadgets.Accountings
{
	public partial class eCashBalance : WeifenLuo.WinFormsUI.Docking.DockContent  
	{
		public eCashBalance()
		{
			InitializeComponent();
		}
            
		private void eCashBalance_Load(object sender, EventArgs e)
		{
			try
			{
                ABSCommonLibrary.CreateGridView(ref gridControl1);
                colHISTORY_DATE.FormatSpecifier = DeclareLibrary.DATE_DISPLAY_FORMAT;
                colTRADING_AMOUNT.FormatSpecifier = DeclareLibrary.NUMBER_FORMAT;
                colLOCKED_AMOUNT.FormatSpecifier = DeclareLibrary.NUMBER_FORMAT;
                colTRUSTED_AMOUNT.FormatSpecifier = DeclareLibrary.NUMBER_FORMAT;
                colBEGIN_AMOUNT.FormatSpecifier = DeclareLibrary.NUMBER_FORMAT;
                colFEE_AMOUNT.FormatSpecifier = DeclareLibrary.NUMBER_FORMAT; 
			}
			catch (Exception ex)
			{
				ABSCommonLibrary.ShowErrorMessage(ex.ToString());
			}
		}

		private void load_grid()
		{
            string account_no = string.Empty;
            DateTime history_date = DeclareLibrary.MARKET_DAY;
            if (valueRow1.Cells["ACCOUNT_NO"].Value != null)
                account_no = valueRow1.Cells["ACCOUNT_NO"].Value.ToString();           
            if (valueRow1.Cells["HISTORY_DATE"].Value != null)
                history_date = Convert.ToDateTime(valueRow1.Cells["HISTORY_DATE"].Value);

            DataSet v_data = ABSCommonLibrary.DoInquiry(
                CommonLibrary.CommonLibrary.BOSC004006, new object[4] { 
                    history_date, account_no, string.Empty, string.Empty });
            gridControl1.SetDataBinding(v_data, v_data.Tables[0].TableName);
		}
		
        //private void btnProcess_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (grdC1Result.RowCount == 0)
        //            return;
        //        if (ABSCommonLibrary.ShowQuestion(
        //            "Ban muon thuc hien cho vay ung truoc tien ban tu dong?") == DialogResult.No)
        //            return;


        //        //object[] p_param = new object[1];
        //        //p_param[0] = DeclareLibrary.MARKET_DAY.ToString(DeclareLibrary.DATE_VALUE_FORMAT);

        //        //if (Convert.ToBoolean(ABSCommonLibrary.DoExecute(CommonLibrary.CommonLibrary.BOSC009002, ref p_param)))
        //        //{
        //        //    ABSCommonLibrary.ShowMessage(
        //        //        "Cho vay ung truoc tu dong phai duoc chay sau khi he thong da ket thuc ngay!");
        //        //    return;
        //        //}
        //        btnProcess.Enabled = false;
        //        object[] p_param = new object[4];
        //        for (int i = 0; i < p_param.GetLength(0); i++)
        //        {
        //            p_param[0] = DeclareLibrary.MARKET_DAY.ToString(DeclareLibrary.DATE_VALUE_FORMAT);
        //            p_param[1] = grdC1Result.Columns["CASH_ID"].CellValue(i).ToString();
        //            p_param[2] = DeclareLibrary.MARKET_DAY.ToString(DeclareLibrary.DATE_VALUE_FORMAT);
        //            p_param[3] = DeclareLibrary.USER_NAME;
        //            ABSCommonLibrary.DoExecute(CommonLibrary.CommonLibrary.BOSC004009, ref p_param);
        //        }
        //        load_grid();
        //    }
        //    catch (Exception ex)
        //    {
        //        ABSCommonLibrary.ShowErrorMessage(ex.ToString());
        //    }
        //}

        private void eCashBalance_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F9)
            {
                try
                {
                    load_grid();
                }
                catch (Exception ex)
                {
                    ABSCommonLibrary.ShowErrorMessage(ex.ToString());
                }
            }
        }

	}
}